import types from './type';
import service from '@/services/branch-hospital';

export default {
  // 获取下属医院列表
  async  getHospitalList ({ commit }, params) {
    const data = await service.apiGetHospitalList(params);
    commit(types.GET_HOSPITAL_LIST, data);
    return data;
  },
  // 修改医院 停用启用医院
  updateHospital ({ commit }, params) {
    return service.apiUpdateHospital(params);
  },
  // 新建医院
  addHospital ({ commit }, params) {
    return service.apiAddHospital(params);
  },
  // 判断医院名称是否存在
  async getHospitalExist ({ commit }, params) {
    const data = await service.apiGetHospitalExist(params);
    commit(types.GET_HOSPITAL_EXIST, data);
    return data;
    // return service.apiGetHospitalExist(params);
  },
  // 获取医院信息详情
  async getHospitalDetail ({ commit }, params) {
    const data = await service.apiGetHospitalDetail(params);
    commit(types.GET_HOSPITAL_DETAIL, data);
    return data;
  },
  // 删除上传图片
  deleteFile ({ commit }, params) {
    return service.apiDeleteFile(params);
  },
  // 医院管理员列表
  async getHospitalManagerList ({ commit }, params) {
    const data = await service.apiGetHospitalManagerList(params);
    commit(types.GET_HOSPITAL_MANAGER_LIST, data);
    return data;
  },
  // 移除医院管理员角色
  deleteManagerRole ({ commit }, params) {
    return service.apiDeleteManagerRole(params);
  },
  // 授权管理列表
  async getAuthManageList ({ commit }, params) {
    const data = await service.apiGetAuthManageList(params);
    commit(types.GET_AUTH_MANAGE_LIST, data);
    return data;
  },
  // 授权 取消授权
  updateAuthModule ({ commit }, params) {
    return service.apiUpdateAuthModule(params);
  },
  // 邀请管理员
  addManager ({ commit }, params) {
    return service.apiAddManager(params);
  },
  // 停用(启用)管理员
  updateManageClose ({ commit }, params) {
    return service.apiUpdateManageClose(params);
  },
  // 删除医院
  deleteHospital ({ commit }, params) {
    return service.apiDeleteHospital(params);
  },
  saveRecipeJurisdiction ({ commit }, params) {
    service.apiGetRecipeJurisdiction(params).then(data => {
      // 这里是医院设置的属性
      localStorage.setItem('HOSPITAl_SETTING_CONFIG', JSON.stringify(data));
      commit('SET_HOSPITAl_SETTING_CONFIG', data);
      commit('GET_HOSPITAL_DETAIL', data);
    });
  },
  // 设置医院中药处方权限是否开放
  setRecipeJurisdiction ({ commit }, params) {
    return service.apiSetRecipeJurisdiction(params);
  },
  // 获取是否开启erp
  getIsOpenErp ({ commit }, params) {
    // commit(types.GET_IS_OPEN_ERP, true);
    return service.apiGetIsOpenERP(params).then(data => {
      commit(types.GET_IS_OPEN_ERP, data);
    });
  }
};
